﻿using DataModels.Dto;
using DataModels.Dto.WorkOrder;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Services.WorkOrder;
using Utils;
using static DataModels.Enums.GeneralEnum;

namespace PropertyManagementWebApi.Controllers.WorkOrder
{
    public class WorkOrderController(WorkOrderService workOrderService) : BaseController
    {
        protected readonly WorkOrderService _workOrderService = workOrderService;

        /// <summary>
        /// 获取工单类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResponseModel GetWorkOrderType(int parentId = -1)
        {
            return _workOrderService.GetWorkOrderType(parentId);
        }
        /// <summary>
        /// 提交工单
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ResponseModel> CreateWorkOrder(CreateWorkOrderInfo info)
        {
            return _workOrderService.CreateWorkOrder(info);
        }
        
        /// <summary>
        /// 取消工单
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public ResponseModel CancelledWorkOrder(discontinueWorkOrder info)
        {
            return _workOrderService.CancelledWorkOrder(info);
        }

        /// <summary>
        /// 催工单
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public ResponseModel UrgentWorkOrder(UrgentWorkOrder info)
        {
            return _workOrderService.UrgentWorkOrder(info);
        }

        /// <summary>
        /// 评价工单
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ResponseModel> ResolvedWorkOrder(ResolvedWorkOrder info)
        {
            return _workOrderService.ResolvedWorkOrder(info);
        }

        /// <summary>
        /// 获取工单列表
        /// </summary>
        /// <param name="info">   0待派单 1待接单 2处理中 3待审核 4已解决 5已关闭 6已取消  </param>
        /// <returns></returns>
        [HttpGet]
        public Task<ResponseModel> GetWorkOrder([FromQuery] GetWorkOrderInfo info)
        {
            return _workOrderService.GetWorkOrder(info);
        }

        /// <summary>
        /// 获取工单详情历史记录
        /// </summary>
        /// <param name="WorkOrderId"></param>
        /// <returns></returns>
        [HttpGet]
        public ResponseModel GetWorkOrderHistory([GeneralRequired] Guid WorkOrderId)
        {
            return _workOrderService.GetWorkOrderHistory(WorkOrderId);
        }
    }
}
